import { _decorator, Component, director, EventTouch, instantiate, Label, Node, Vec3 } from 'cc';
import { backHouse } from './setScene';
const { ccclass, property } = _decorator;
@ccclass('touchController')
export class touchController extends Component {

    @property(Node)
    canvasNode: Node = null;

    currentScene: boolean;

    start() {
        globalThis.touchController = this;
    }

    Touch() {
        const cows = this.node.parent
        let instantiatenode = instantiate(this.node);
        const arry = [350, 322, 272, 212, 172, 102, 50];
        let randomy = Math.floor(Math.random() * arry.length);

        // 从数组中获取随机选中的数
        const randomNumy = arry[randomy];

        cows.addChild(instantiatenode); // 将克隆的节点添加到父节点中
        instantiatenode.setPosition(806, randomNumy, 0);
        
        this.lableChange()
        this.randomy(randomNumy)
    }
    lableChange() {
        let tsname = this.canvasNode.getComponent(backHouse)
        let label = tsname.JIFEN.getComponent(Label)
        
        tsname.jifen++;
        label.string = '积分:' + tsname.jifen;
    }

    //停止游戏的函数
    stopGame() {
        console.log('游戏停止了');

        this.node.active = false;
    }

    randomy(y){

        globalThis.onTouch.touchHorse(y)
    }

}